package com.example.mybatisplus.service.impl;

import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.mapper.FirstAppointmentMapper;
import com.example.mybatisplus.model.domain.DutyTime;
import com.example.mybatisplus.model.domain.FirstAppointment;
import com.example.mybatisplus.service.DutyTimeService;
import com.example.mybatisplus.service.FirstAppointmentService;
import com.example.mybatisplus.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mybatisplus.mapper.FirstApoStatusMapper;
import com.example.mybatisplus.model.domain.FirstApoStatus;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.FirstApoStatusService;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 学生的初访情况 服务实现类
 * </p>
 *
 * @author cft
 * @since 2022-06-27
 */
@Service
public class FirstApoStatusServiceImpl extends ServiceImpl<FirstApoStatusMapper, FirstApoStatus> implements FirstApoStatusService {


    @Autowired
    UserAccountService userAccountService;

    @Autowired
    FirstApoStatusService firstApoStatusService;
    @Autowired
    FirstApoStatusMapper firstApoStatusMapper;
    @Autowired
    FirstAppointmentMapper firstAppointmentMapper;

    /*
    * author:tqq
    * 查看需要被安排且还未被咨询助理安排过的初访结果
    * */
    @Override
    public Page<FirstApoStatus> dispayFapoRecord(PageDTO pageDTO) {
        Page<FirstApoStatus> page = new Page<>(pageDTO.getPageNo(),pageDTO.getPageSize());
        QueryWrapper<FirstApoStatus> wrapper = new QueryWrapper<>();
        wrapper.eq("f_result","安排咨询");
        page = super.page(page,wrapper);
        return page;
    }

    /*
     * author:jrh
     * function:初访员分配的初访任务
     */
    @Override
    public List<FirstApoStatus> getFInfo() {
        QueryWrapper<FirstApoStatus> wrapper=new QueryWrapper<>();
        wrapper.eq("f_viewer_id", SessionUtils.getCurrentUserInfo().getUserId());
        return firstApoStatusService.list(wrapper);
    }

    /*
     * author:tqq
     * function:根据当前登录学生查询初访结果信息
     */
    @Override
    public List<FirstApoStatus> getBystuId(Long userId) {
        QueryWrapper<FirstAppointment> wrapper = new QueryWrapper<>();
        wrapper.eq("stu_id", userId);
        List<FirstAppointment> list0 = firstAppointmentMapper.selectList(wrapper);
        List<FirstApoStatus> list = new ArrayList<>();
        for (int i = 0; i < list0.size(); i++) {
            QueryWrapper<FirstApoStatus> wrapper1 =new QueryWrapper<>();
            wrapper1.eq("f_apo_id",list0.get(i).getFApoId());
            list.add(firstApoStatusService.getOne(wrapper1));
        }
        return list;
    }


}
